<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

</head>
<body>
<div id="app">

    <fieldset style="margin: 150px auto;width: 500px;border: 0px">

        <legend>修改密码:</legend>
        <br> <br>
        <el-form :model="passwordInfo" status-icon :rules="rules" ref="passwordInfo" label-width="100px" class="demo-ruleForm">
            <el-form-item label="旧密码" prop="password">
                <el-input  type="password"  v-model="passwordInfo.password" ></el-input>
            </el-form-item>
            <el-form-item label="新密码" prop="newPassword">
                <el-input type="password" v-model="passwordInfo.newPassword" ></el-input>
            </el-form-item>
            <el-form-item label="确认密码" prop="passwordNew">
                <el-input type="password" v-model="passwordInfo.passwordNew" ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('passwordInfo')">确认修改</el-button>
                <el-button @click="resetForm('passwordInfo')">重置</el-button>
            </el-form-item>
        </el-form>
    </fieldset>

</div>
<script>
    var haha=new Vue({
        el:"#app",
        data:{
            passwordInfo:{},
            rules: {

                password: [
                    {required: true, message: '请输入旧密码', trigger: 'blur'},
                    {min: 2, max: 6, message: '长度在 2 到 6个字符', trigger: 'blur'}
                ],

                newPassword: [
                    {required: true, message: '请输入新密码', trigger: 'blur'},
                    {min: 2, max: 6, message: '长度在 2 到 6个字符', trigger: 'blur'}
                ],

                passwordNew: [
                    {required: true, message: '请再次输入新密码', trigger: 'blur'},
                    {min: 2, max: 6, message: '长度在 2 到 6个字符', trigger: 'blur'}
                ]
            }
        },
        methods:{
            submitForm(formName) {
                haha.$refs[formName].validate((valid) => {
                    if (valid) {
                        $.post("/ssm/admin/cipher",haha.passwordInfo,function (data) {
                            if (data.code==2){
                                haha.$notify.error({
                                    title: '温馨提示',
                                    message: data.msg
                                });
                            }else if (data.code==1) {
                                window.location.href="/ssm/myself/logout.html";
                            }
                        });
                    }
                });
            },
            resetForm(formName) {
                haha.$refs[formName].resetFields();
            }
        }
    });

</script>
</body>
</html>